//
//  UIView+AddOnes.m
//  HJiOSLib
//
//  Created by Ji Hu on 12-8-2.
//  Copyright (c) 2012年 爱辅导. All rights reserved.
//

#import "UIView+AddOnes.h"

@implementation UIView (AddOnes)

-(id)AOloadReuseableView:(Class)viewclass{
    
    for (UIView *child in self.subviews) {
        
        if ([child isKindOfClass:viewclass]) {
            return child;
        }
        
    }
    
    return nil;
    
}

-(void)AOshowLoading{
    
    [self AOshowLoadingAt:self.center];
    
}

-(void)AOstopLoading{
    
    UIActivityIndicatorView *activityIndicator = [self AOloadReuseableView:[UIActivityIndicatorView class]];
    
    if (activityIndicator!=nil) {
        [activityIndicator stopAnimating];
    }
}

-(void)AOshowLoadingAt:(CGPoint)center{
    
    UIActivityIndicatorView *activityIndicator = [self AOloadReuseableView:[UIActivityIndicatorView class]];
    
    if (activityIndicator==nil) {
        activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        activityIndicator.color=[UIColor grayColor];
        activityIndicator.hidesWhenStopped=YES;
        [activityIndicator setCenter:center];
        
        [self addSubview:activityIndicator];
        [self bringSubviewToFront:activityIndicator];
        [activityIndicator startAnimating];
        [activityIndicator release];
    }else {
        [activityIndicator setCenter:center];
        [activityIndicator setHidden:NO];
        [self bringSubviewToFront:activityIndicator];
        [activityIndicator startAnimating];
    }
}

@end
